import { ref } from "vue"
import type { LikeCollectParams, QuestionList } from "@/types/data"
import { getLikeCollect } from "@/api/article"
export const useLikeCollect = (optType: 1 | 2) => {
  const isFinished = ref(false)
  const loading = ref(false)
  const queryParams = ref<LikeCollectParams>({
    optType,
    page: 1,
    pageSize: 10,
  })
  const queryList = ref<QuestionList>({
    current: 1,
    pageTotal: 10,
    pageSize: 10,
    total: 0,
    rows: [],
  })
  const onLoad = async () => {
    const { data } = await getLikeCollect(queryParams.value)
    queryList.value = { ...data, rows: [...queryList.value.rows, ...data.rows] }
    isFinished.value = data.pageTotal <= queryParams.value.page
    loading.value = false
    isFinished.value && queryParams.value.page++
  }
  return {
    queryParams,
    queryList,
    onLoad,
    isFinished,
    loading,
  }
}
